package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName: ddressBookMapper
 * Package: com.sky.mapper
 * Description:
 *
 * @Author 八云
 * @Create 2025/3/23 23:04
 * @Version 1.0
 */

@Mapper
public interface AddressBookMapper {
    void save(AddressBook addressBook);

    List<AddressBook> list(AddressBook addressBook);

    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}" )
    void setDefaultAll(AddressBook addressBook);

    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId} and id = #{id}" )
    void setDefault(AddressBook addressBook);

    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook getDefault(Long currentId);

    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void remove(Long id);
}
